package com.hp.gui.tab;


import javax.swing.*;
import java.awt.*;

/**
 * DnDTabbedPaneExe.java
 * Description: Initialize the UI and run the test.
 */
public class DnDTabbedPaneExe {
    public DnDTabbedPaneExe() {
        initUI();
    }

    public void initUI() {
        JFrame test = new JFrame("Drag and Drop Tabs Test");
        test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        test.setLocation(400, 400);
        test.setSize(1000, 450);

        // Our DnDTabbedPane here.
        DnDTabbedPane tabs = new DnDTabbedPane();
        DnDTabbedPane tabs2 = new DnDTabbedPane();

        JPanel panel = new JPanel();
        panel.add(new JButton("1"));
        panel.add(new JButton("123"));
        ImageIcon icon = new ImageIcon("smallChrome.JPG");
        tabs.addTab("Table", icon, initTable());
        tabs.addTab("ButtonGroup", icon, panel);
        tabs.addTab("JTextArea", icon, new JTextArea("2"));
        tabs.addTab("JLabel", icon, new JLabel("3"));
        tabs.addTab("Button", icon, new JButton("4"));
        tabs.addTab("Table2", icon, initTable());

        tabs2.addTab("Story", icon, new JTextArea("This is a story"));
        tabs2.addTab("A Button", icon, new JButton("A"));
        tabs2.addTab("B Button", icon, new JButton("B"));

        test.add(initTree(), BorderLayout.WEST);
        test.add(tabs, BorderLayout.EAST);
        test.add(tabs2, BorderLayout.CENTER);
        test.setVisible(true);
    }

    /*
     * Main
     */
    public static void main(String[] args) {
        DnDTabbedPaneExe frame = new DnDTabbedPaneExe();
    }


    // Methods initialize some tabs

    /*
     * Initialize JTree with default JTree example while new JTree()
     */
    public class InitJTree extends JTree {
        public InitJTree() {
            super();
            this.setAutoscrolls(true);
        }
    }

    /*
     * Return a JScrollPane with draggable JTree
     */
    private JScrollPane initTree() {
        JTree myTree;
        myTree = new JTree();
        myTree.setDragEnabled(true);
        myTree.setTransferHandler(new TransferHandler("tree"));// -----TreeTransferHandler here-------
        JScrollPane treePane = new JScrollPane(myTree);
        return treePane;
    }

    /*
     * Return a JScrollPane with table accept the draggable Tree nodes
     */
    private JScrollPane initTable() {
        JTable table = new JTable(8, 3);
        for (int i = 0; i < 8; i++) {
            table.setValueAt(i + ",0", i, 0);
        }
        table.setTransferHandler(new TransferHandler("table"));// -----TableTransferHandler here------
        return new JScrollPane(table);
    }
}